﻿@model BrandModel
@inject SeoSettings seoSettings
@inject IPageHeadBuilder pagebuilder
@{
    Layout = "_TwoColumns";

    pagebuilder.AddTitleParts(!string.IsNullOrEmpty(Model.MetaTitle) ? Model.MetaTitle : Model.Name);
    pagebuilder.AddMetaDescriptionParts(Model.MetaDescription);
    pagebuilder.AddMetaKeywordParts(Model.MetaKeywords);

    var canonicalUrlsEnabled = seoSettings.CanonicalUrlsEnabled;
    if (canonicalUrlsEnabled)
    {
        var collectionUrl = Url.RouteUrl("Brand", new { Model.SeName }, Url.ActionContext.HttpContext.Request.Scheme);
        pagebuilder.AddCanonicalUrlParts(collectionUrl);
    }
}

<div class="page brand-page">
    <h1 class="generalTitle h2">@Model.Name</h1>
    @await Component.InvokeAsync("Widget", new { widgetZone = "branddetails_top", additionalData = Model.Id })
    @*Rendering description section*@
    @if (!string.IsNullOrWhiteSpace(Model.Description))
    {
        <div class="card collection-description">
            <div class="card-body">
                @Html.Raw(Model.Description)
            </div>
        </div>
    }
    @await Component.InvokeAsync("Widget", new { widgetZone = "branddetails_before_featured_products", additionalData = Model.Id })
    @*Rendering featured products section*@
    @await Component.InvokeAsync("Widget", new { widgetZone = "branddetails_after_featured_products", additionalData = Model.Id })
    <div id="catalog-products">
        @await Component.InvokeAsync("Widget", new { widgetZone = "branddetails_before_filters", additionalData = Model.Id })
        <partial name="Partials/Selectors"/>
        <template v-if="catalog.Model.Products.length > 0">
            <template v-if="catalog.Model.PagingFilteringContext.ViewMode == 'grid'">
                <div class="col-12 product-grid px-0">
                    <div class="row">
                        <template v-for="Model in catalog.Model.Products">
                            <div class="col-lg-4 col-sm-6 col-6 product-container mb-2">
                                <partial name="Partials/CatalogProductGridView"/>
                            </div>
                        </template>
                    </div>
                </div>
            </template>
            <template v-else>
                <div class="product-list">
                    <div class="col-12">
                        <div class="row">
                            <template v-for="Model in catalog.Model.Products">
                                <partial name="Partials/CatalogProductListView"/>
                            </template>
                        </div>
                    </div>
                </div>
            </template>
            <partial name="Partials/Pagination"/>
        </template>
        <template v-else>
            <div class="alert alerty-info my-3">
                @Loc["search.noresultstext"]
            </div>
        </template>
    </div>

    @*Rendering bottom description section*@
    @if (!string.IsNullOrWhiteSpace(Model.BottomDescription))
    {
        <div class="card brand-description">
            <div class="card-body">
                @Html.Raw(Model.BottomDescription)
            </div>
        </div>
    }

    @await Component.InvokeAsync("Widget", new { widgetZone = "branddetails_bottom", additionalData = Model.Id })
</div>

@section filters
{
    @*Rendering filtering section*@
    @if (Model.PagingFilteringContext.SpecificationFilter.Enabled)
    {
        <partial name="Partials/Filtering"/>
    }
}

<partial name="Partials/ModelScript" model="@Json.Serialize(Model)"/>